//
//  ZZBaseViewController.m
//  OCFrame
//
//  Created by hfzhangzhang on 2017/1/4.
//  Copyright © 2017年 hfzhangzhang. All rights reserved.
//

#import "ZZBaseViewController.h"

@interface ZZBaseViewController ()

@property (nonatomic, strong, readonly) UIBarButtonItem *backBarButtonItem;

@end

@implementation ZZBaseViewController

@synthesize backBarButtonItem = _backBarButtonItem;

- (void)willMoveToParentViewController:(UIViewController *)parent {
    [super willMoveToParentViewController:parent];
    if ((self.navigationController && [self.navigationController.viewControllers indexOfObject:self] != 0) ||
        ([parent isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)parent viewControllers] indexOfObject:self] != 0)) {
        if (self.navigationItem.leftBarButtonItem != self.backBarButtonItem) {
            self.navigationItem.leftBarButtonItem = self.backBarButtonItem;
        }
    } else {
        self.navigationItem.leftBarButtonItem = nil;
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self setNeedsStatusBarAppearanceUpdate];
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (UIBarButtonItem *)backBarButtonItem {
    if (_backBarButtonItem == nil) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 0, 8.5, 15);
        //[button addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
        _backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    }
    return _backBarButtonItem;
}

- (void)setRightBarButtonWithTitle:(NSString *)title target:(id)target action:(SEL)action {
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.titleLabel.font = [UIFont systemFontOfSize:16];
//    [button setTitleColor:[UIColor tc1Color] forState:UIControlStateNormal];
//    CGSize size=[title sizeWithFont:[UIFont systemFontOfSize:16] maxW:100];
//    button.frame = CGRectMake(0, 0, size.width+5, 40);
//    [button setTitle:title forState:UIControlStateNormal];
//    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
//    self.navigationItem.rightBarButtonItem.tintColor =[UIColor tc1Color];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationFade;
}





@end
